package com.acwing.partition11;

import java.io.*;
import java.util.Arrays;

public class AC1020潜水员 {

    private static final int N = 85, M = 25, K = 1010;
    private static int[] w1 = new int[K], w2 = new int[K], v = new int[K];
    private static int[][] f = new int[N][M];
    private static int n, m, k;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        m = nextInt(); n = nextInt(); k = nextInt();
        for (int i = 1; i <= k; i++) {
            w2[i] = nextInt();
            w1[i] = nextInt();
            v[i] = nextInt();
        }
        for (int i = 0; i < N; i++) Arrays.fill(f[i], 0x3f3f3f3f);
        f[0][0] = 0;
        for (int i = 1; i <= k; i++) {
            for (int a = n; a >= 0; a--) {
                for (int b = m; b >= 0; b--) {
                    f[a][b] = Math.min(f[a][b], f[Math.max(0, a - w1[i])][Math.max(0, b - w2[i])] + v[i]);
                }
            }
        }
        writer.println(f[n][m]);
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}